package com.carrot.api.controller.system;

import com.google.common.collect.Lists;
import com.carrot.common.core.controller.BaseController;
import com.carrot.common.core.domain.AjaxResult;
import com.carrot.common.core.domain.entity.SysStation;
import com.carrot.common.core.domain.vo.NodeVo;
import com.carrot.common.enums.EquipmentTypeEnum;
import com.carrot.system.service.ISysStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system/dict")
public class DictController extends BaseController {

    @Autowired
    private ISysStationService stationService;

    /**
     * 场站列表
     */
    @GetMapping("get-station-list")
    public AjaxResult getStationList() {
        List<SysStation> stationList = stationService.query()
                .orderByAsc("create_time")
                .list();

        return AjaxResult.success(stationList);
    }

    /**
     * 设备列表
     */
    @GetMapping("get-equipment-list")
    public AjaxResult getEquipmentList() {

        List<NodeVo> list = Lists.newArrayList();
        for (EquipmentTypeEnum typeEnum : EquipmentTypeEnum.values()) {
            NodeVo nodeVo = new NodeVo();
            nodeVo.setId(typeEnum.getVal());
            nodeVo.setName(typeEnum.getName());
            list.add(nodeVo);
        }
        return AjaxResult.success(list);
    }

}
